package com.teddy.controller;

import java.io.IOException;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.swt.widgets.Composite;
import org.xml.sax.SAXException;

import com.teddy.model.Database;
import com.teddy.view.BaseGUI;


public class RDFSchemaControl {
	
	private static ResourceBundle resourceBundle =
		ResourceBundle.getBundle("teddy");
	
	private BaseGUI baseGUI;
	private Database database;
	
	boolean startup = true; 
	
	public RDFSchemaControl(Composite parent) throws IOException, ParserConfigurationException, SAXException {
		parent.getShell().setText( RDFSchemaControl.getResourceString( "window.title" ));
		initResources();
		createGUI( parent );
		startup = false;
	}
	
	private void initResources() {
		setDatabase(new Database());
	}
	
	private void createGUI( Composite parent) throws IOException, ParserConfigurationException, SAXException {
		baseGUI = new BaseGUI(this) ;
		baseGUI.createGUIPage(parent);
	}

	public void setDatabase(Database database) {
		this.database = database;
	}

	public Database getDatabase() {
		return database;
	}

	/**
	 * Gets a string from the resource bundle.
	 * We don't want to crash because of a missing String.
	 * Returns the key if not found.
	 */
	public static String getResourceString(String key) {
		try {
			return resourceBundle.getString(key);
		} catch (MissingResourceException e) {
			return key;
		} catch (NullPointerException e) {
			return "!" + key + "!";
		}			
	}
}
